package com.yincheng.oms.bussiness.order;

import java.io.IOException;
import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yincheng.oms.bussiness.order.entity.OrderLog;
import com.yincheng.oms.bussiness.order.mapper.OrderLogMapper;
import com.yincheng.oms.bussiness.util.Page;
import com.yincheng.oms.bussiness.util.excel.ExcelExportUtils;

@Service
public class OrderListService {

	@Autowired
	private OrderListMapper orderListMapper;
	
	@Autowired
	private OrderLogMapper orderLogMapper;
	
	public Pair<Integer, List<QueryResultRowBean>> getListByParam(QueryParamBean param){
		Page page = param.getPage();
		int total = orderListMapper.countByParam(param);
		page.setTotal(total);
		List<QueryResultRowBean> list = orderListMapper.selectByParam(param);
		return Pair.of(total, list);
	}
	
	
	public ExcelExportUtils<OrderExcel> export(QueryParamBean param) throws IOException {
		List<OrderExcel> list = orderListMapper.selectExcelByParam(param);
		for (OrderExcel orderExcel : list) {
			String orderId = orderExcel.getOrderId();
			List<OrderLog> orderLogs = orderLogMapper.selectByOrderId(orderId);
			orderExcel.setOrderLogs(orderLogs);
		}
		return new ExcelExportUtils<>(OrderExcel.class, list);
	}
}
